<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px" @submit.native.prevent>
      <el-form-item label="姓名" prop="nickName">
        <el-input
            v-model="queryParams.nickName"
            placeholder="请输入姓名"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="experimentList">
      <el-table-column label="负责人工号" align="center" width="100" prop="userCode"/>
      <el-table-column label="姓名" align="center" prop="nickName"/>
      <el-table-column label="电话" align="center" prop="phonenumber"/>
      <el-table-column label="项目数量" align="center" prop="count"/>
      <el-table-column label="项目详情" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" @click="showProject(scope.row.userId)">查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />

    <!-- 添加或修改实验类型管理对话框 -->
    <el-dialog :title="title" v-model="open" width="800px" append-to-body>
      <el-table :data="projectList">
        <el-table-column label="项目编号" align="center" prop="code"/>
        <el-table-column label="项目名称" align="center" prop="projectName"/>
        <el-table-column label="项目进度情况" align="center">
          <template #default="scope">
            <span :style="stepList[scope.row.projectStyle].style"
                  style="font-size: 13px;color: white;padding: 6px 8px;border-radius: 10px;margin-right: 8px">
            {{ stepList[scope.row.projectStyle].t1 }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="项目回款情况" align="center" prop="hasPay">
          <template #default="scope">
            <span>第 {{ scope.row.hasPay }} 次回款</span>
          </template>
        </el-table-column>
      </el-table>
      <pagination
          v-show="projectTotal>0"
          :total="projectTotal"
          v-model:page="queryProject.pageNum"
          v-model:limit="queryProject.pageSize"
          @pagination="getProjectList"
      />
    </el-dialog>
  </div>
</template>

<script setup name="Leader">
import {listAll, listProject} from "@/api/person/leader.js";

const {proxy} = getCurrentInstance();

const experimentList = ref([]);

const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);
const title = ref("");

const stepList = ref([
  {style: {'background-color': '#7FFF00'}, t1: '项目录入', t2: '项目管理员'},
  {style: {'background-color': '#15B707'}, t1: '样品录入', t2: '样品管理员'},
  {style: {'background-color': '#31CCF1'}, t1: '实验录入', t2: '实验管理员'},
  {style: {'background-color': '#F62D25'}, t1: '实验中', t2: '实验分发员'},
  {style: {'background-color': '#EDEF1E'}, t1: '财务结算', t2: '财务'},
  {style: {'background-color': '#3E59DC'}, t1: '结题', t2: '项目负责人'}
])

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    nickName: null
  },
  queryProject: {
    pageNum: 1,
    pageSize: 10,
    id: null
  },
  rules: {}
});

const {queryParams, form, rules, queryProject} = toRefs(data);

/** 查询实验类型管理列表 */
function getList() {
  loading.value = true;
  listAll(queryParams.value).then(response => {
    experimentList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

const open = ref(false);
const projectList = ref([]);
const projectTotal = ref(0);

function showProject(id) {
  queryProject.value.userId=id;
  getProjectList();
}
function getProjectList(){
  listProject(queryProject.value).then(res=>{
    projectList.value=res.rows;
    projectTotal.value=res.total;
    open.value=true;
  })
}

getList();
</script>
